import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  {
    path:'/login',
    name:'login',
    component:()=> import ('../views/login.vue')
  },
  {
    path:'/',
    name:'index',
    redirect:'/home',
    component:()=> import ('../views/pages/index.vue'),
    children:[
      {
        path:'home',
        name:'home',
        component:()=> import ('../views/pages/home.vue')
      },
      {
        path:'allshop',
        name:'allshop',
        component:()=> import ('../views/pages/allshop.vue')
      },
      {
        path:'about',
        name:'about',
        component:()=> import ('../views/pages/about.vue')
      },
    ]
  },
  {
    path:'/shopcar',
    name:'shopcar',
    component:()=> import ('../views/shopcar.vue'),
    beforeEnter: (to, from, next) => {
     if(localStorage.getItem('token')){
       next();
     }else{
       alert('请先登录')
       next('/login');
     }
    }
  },
  {
    path:'/collect',
    name:'collect',
    component:()=> import ('../views/collect'),
  },
 
]

const router = new VueRouter({
  routes
})

export default router
